<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>

<body class="white-bg">
<style>
    .content{
        margin-top:6px ;
    }
    .form-group{
        margin-bottom: 0px;
    }
    #category1,#category2,#category3{
        border: none!important;
        appearance:noe!important;
        -moz-appearance:inherit;
        -webkit-appearance:inherit;
        background-color: transparent;
    }
    #area1,#area2,#area3{
        border: none!important;
        appearance:noe!important;
        -moz-appearance:inherit;
        -webkit-appearance:inherit;
        background-color: transparent;
    }
</style>


<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-jiaotong-info" th:object="${jiaotong}">
        <input id="jtId" name="jtId" th:field="*{jtId}"  type="hidden">
        <input id="jtRoleName" name="jtRoleName" th:field="*{jtRoleName}"  type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <div id="jtTitle" class="content" name="jtTitle" th:utext="*{jtTitle}" type="text"></div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">变更日期：</label>
            <div class="col-sm-8">
                <div id="jtNewChangedate" name="jtNewChangedate"  th:utext="*{jtNewChangedate}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">创建者：</label>
            <div class="col-sm-8">
                <div id="createBy" name="createBy" th:utext="*{createBy}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">创建日期：</label>
            <div class="col-sm-8">
                <div id="newcreateTime" name="newcreateTime" th:utext="*{newcreateTime}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">更新者：</label>
            <div class="col-sm-8">
                <div id="updateBy" name="updateBy" th:utext="*{updateBy}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">更新日期：</label>
            <div class="col-sm-8">
                <div id="newupdateTime" name="newupdateTime" th:utext="*{newupdateTime}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8">
                <div id="jtProcess" name="jtProcess" th:utext="*{jtProcess}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">审批状态：</label>
            <div class="col-sm-8">
                <div id="jtStatus" name="jtStatus" th:utext="*{jtStatus}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">信息来源：</label>
            <div class="col-sm-8">
                <div id="jtOriginal" name="jtOriginal" th:utext="*{jtOriginal}" class="content" type="text"></div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">一级类别：</label>
            <div class="col-sm-8">
                <select id="category1"  class="content"  name="jtLb1id"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">二级类别：</label>
            <div class="col-sm-8">
                <select id="category2"  class="content"  name="jtLb2id"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">三级类别：</label>
            <div class="col-sm-8" >
                <select id="category3"  class="content"  name="jtLb3id"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">所在省：</label>
            <div class="col-sm-8">
                <select id="area1"  class="content"  name="jtProvinceid"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">所在市：</label>
            <div class="col-sm-8">
                <select id="area2"  class="content"  name="jtCityid"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">所在县：</label>
            <div class="col-sm-8" >
                <select id="area3"  class="content"  name="jtCountryid"
                        data-rel="chosen" disabled="disabled">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">总名称：</label>
            <div class="col-sm-8">
                <div id="jtZongmc" name="jtZongmc" th:utext="*{jtZongmc}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">总编号：</label>
            <div class="col-sm-8">
                <div id="jtZongbh" name="jtZongbh" th:utext="*{jtZongbh}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分段名称：</label>
            <div class="col-sm-8">
                <div id="jtFendmc" name="jtFendmc" th:utext="*{jtFendmc}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分段编号：</label>
            <div class="col-sm-8">
                <div id="jtFendbh" name="jtFendbh" th:utext="*{jtFendbh}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">级别：</label>
            <div class="col-sm-8">
                <div id="jtLevels" name="jtLevels" th:utext="*{jtLevels}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">里程：</label>
            <div class="col-sm-8">
                <div id="jtLicheng" name="jtLicheng" th:utext="*{jtLicheng}" class="content" type="text"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">详细内容：</label>
            <div class="col-sm-8">
                <div class="content" th:utext="*{jtDetails}"></div>
            </div>
        </div>
    </form>

</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
<script type="text/javascript" th:inline="javascript">
    var prefix = ctx + "system/jiaotong";
    var prefix1 = ctx + "system/category";
    var prefix2 = ctx + "system/area";
    $(function() {

        var lb1 =   [[${jiaotong.jtLb1id}]];
        var lb2 =   [[${jiaotong.jtLb2id}]];
        var lb3 =   [[${jiaotong.jtLb3id}]];

        var szx1 =   [[${jiaotong.jtProvinceid}]];
        var szx2 =   [[${jiaotong.jtCityid}]];
        var szx3 =   [[${jiaotong.jtCountryid}]];

        initCategrey(lb1,lb2,lb3);
        initArea(szx1,szx2,szx3);
        $('.summernote').summernote({
            height : '220px',
            lang : 'zh-CN',
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this);
                }
            }
        });
        var content = $("#jtDetails").val();
        $('#editor').summernote('code', content);
    });

    // 上传文件
    function sendFile(file, obj) {
        var data = new FormData();
        data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function(result) {
                if (result.code == web_status.SUCCESS) {
                    // $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    $(obj).summernote('editor.insertImage', img_root + result.fileName, result.fileName);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function(error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }

    $("#form-jiaotong-info").validate({
        rules: {
            xxxx: {
                required: true,
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/info", $('#form-jiaotong-info').serialize());
        }
    }


    function initCategrey(jtLb1id,jtLb2id,jtLb3id) {


        cate1(jtLb1id);
        cate2(jtLb1id,jtLb2id);
        cate3(jtLb2id,jtLb3id);
        $("#category1").change(function () {
            cate2($("#category1").val());

        });
        $("#category2").change(function () {
            cate3($("#category2").val());
        });

    }
    function cate1(id) {
        $.get(
            prefix1 + "/list?parentId=100&deptId=101",
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {

                        if(value.deptId ==id )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";

                    });
                    $("#category1").html(result);
                }
            }, "json");
    }

    function cate2(id,deptId) {
        $.get(
            prefix1 + "/list?parentId=101",
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {

                        if(value.deptId ==deptId )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";

                    });
                    $("#category2").html(result);

                }
            }, "json");
    }
    function cate3(id,deptId) {
        $.get(
            prefix1 + "/list?parentId=" + id ,
            function (data) {
                if (data) {
                    var result = '';
                    $.each(data, function (n, value) {
                        if(value.deptId ==deptId )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                    });

                    $("#category3").html(result);
                }
            }, "json");
    }

    function initArea(jtProvinceid,jtCityid,jtCountryid) {


        farea1(jtProvinceid);
        farea21(jtProvinceid,jtCityid);
        farea3(jtCityid,jtCountryid);
        $("#area1").change(function () {
            farea2($("#area1").val());

        });
        $("#area2").change(function () {
            farea3($("#area2").val());
        });

    }
    function farea1(id) {
        $.get(
            prefix2 + "/list?parentId=1",
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {

                        if(value.deptId ==id )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";

                    });
                    $("#area1").html(result);
                }
            }, "json");
    }

    function farea2(id,deptId) {
        $.get(
            prefix2 + "/list?parentId="+ id,
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {


                        if(value.deptId ==deptId )
                        {
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        }
                        else
                        {
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                            if(n==0)
                            {
                                farea3(value.deptId);
                            }
                        }
                    });
                    $("#area2").html(result);

                }
            }, "json");
    }

    function farea21(id,deptId) {
        $.get(
            prefix2 + "/list?parentId="+ id,
            function (data) {
                if (data) {
                    var result = "";
                    $.each(data, function (n, value) {


                        if(value.deptId ==deptId )
                        {
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        }
                        else
                        {
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                        }
                    });
                    $("#area2").html(result);

                }
            }, "json");
    }

    function farea3(id,deptId) {
        $.get(
            prefix2 + "/list?parentId=" + id ,
            function (data) {
                if (data) {
                    var result = '';
                    $.each(data, function (n, value) {
                        if(value.deptId ==deptId )
                            result += "<option selected= 'true' value='" + value.deptId + "'>" + value.deptName + "</option>";
                        else
                            result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
                    });

                    $("#area3").html(result);
                }
            }, "json");
    }

</script>
</body>
</html>
